package com.feng.financial.seller.controller;

import com.feng.financial.common.querydsl.FetchResponse;
import com.feng.financial.common.web.Range;
import com.feng.financial.common.web.WebCommonResponse;
import com.feng.financial.common.web.WebCommonResponseBuilder;
import com.feng.financial.entity.OrderTEntity;
import com.feng.financial.entity.enums.OrderStatus;
import com.feng.financial.entity.enums.OrderType;
import com.feng.financial.seller.service.OrderTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("order")
public class OrderTController {

    @Autowired
    private OrderTService orderTService;

    @PostMapping("findAllByRange")
    public WebCommonResponse<FetchResponse<OrderTEntity>> findAllByRange(@RequestBody Range range){
        OrderTEntity orderTEntity = new OrderTEntity();
        FetchResponse<OrderTEntity> response = orderTService.findAllByPage(orderTEntity, range);
        return new WebCommonResponseBuilder<FetchResponse<OrderTEntity>>().success().build(response);
    }

    @GetMapping("save")
    public OrderTEntity save(){
        OrderTEntity orderTEntity = new OrderTEntity();
        orderTEntity.setOrderId(UUID.randomUUID().toString());
        orderTEntity.setAmount(new BigDecimal(1000001));
        orderTEntity.setChanId("10000");
        orderTEntity.setProductId("10101010");
        orderTEntity.setChanUserId("0001");
        orderTEntity.setOrderType(OrderType.APPLY);
        orderTEntity.setOrderStatus(OrderStatus.INIT);
        orderTEntity.setOuterOrderId("202020220");
        orderTEntity.setMemo("备注");
        orderTEntity.setCreateAt(new Timestamp(System.currentTimeMillis()));
        orderTEntity.setUpdateAt(new Timestamp(System.currentTimeMillis()));
        return orderTService.saveOrder(orderTEntity);
    }

}
